Embedding Banners
Embed a customizable banner in your application.
SwiftUI
Adding the NudgeAppComponentView
To integrate the NudgeAppComponentView
into your SwiftUI layout, add it to a container view such as VStack
, HStack
, or ZStack
:
NudgeAppComponentView(id: "widget_id")
.fixedSize(horizontal: false, vertical: true)
Note: It is strongly recommended to use the
.fixedSize()
modifier to avoid size inconsistencies.
UIKit
Using Storyboard
-
Drag an empty
UIView
onto your storyboard and set the desired size constraints. -
Select the view, and from the class inspector, assign it to
NudgeAppComponent
. -
Create an outlet for the view in your class.
-
Assign an
id
to the view:view.id = "widget_id"
Using a Custom View
-
Initialize the
NudgeAppComponent
class:let nudgeAppComponent = NudgeAppComponent()
-
Assign an
id
:nudgeAppComponent.id = "widget_id"
-
Add it to the desired subview:
self.view.addSubview(nudgeAppComponent)
-
Apply Auto Layout constraints to fit your view hierarchy:
nudgeAppComponent.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
nudgeAppComponent.leadingAnchor.constraint(equalTo: view.leadingAnchor),
nudgeAppComponent.trailingAnchor.constraint(equalTo: view.trailingAnchor),
nudgeAppComponent.centerXAnchor.constraint(equalTo: view.centerXAnchor),
nudgeAppComponent.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])